草庐IT

Java MVC - 感觉我不明白

全部标签

c++ - 为什么我的 T& 和 T&& 复制构造函数不明确?

#includeusingnamespacestd;classMyclass{private:inti;public:templateMyclass(U&lvalue):i(lvalue){coutMyclass(U&&rvalue):i(rvalue){cout错误信息:rightvalue.cpp:Infunction‘intmain(int,char**)’:rightvalue.cpp:15:12:error:callofoverloaded‘Myclass(Myclass&)’isambiguousrightvalue.cpp:15:12:note:candidatesare

c++ - 具有多重继承的 operator() 定义不明确

我用GCC(4.2.1Applebuild5664)编译这段代码#includeusingstd::size_t;templatestructindex{};structa{voidoperator()(size_tconst&){}};structb{templatevoidoperator()(indexconst&){}};structc:publica,publicb{};intmain(intargc,charconst*argv[]){cvc;vc(1);return0;}并给我以下错误:main.cpp:Infunction‘intmain(int,constchar**

c++ - 对基类模板成员函数的访问不明确

在VisualStudio2008中,编译器无法解析下面_tmain中对SetCustomer的调用并使其明确:templatestructProducer{voidSetConsumer(TConsumer*consumer){consumer_=consumer;}TConsumer*consumer_;};structAppleConsumer{};structMeatConsumer{};structShillyShallyProducer:publicProducer,publicProducer{};int_tmain(intargc,_TCHAR*argv[]){Shil

c++ - 不明确的 C++ 编译器错误

以下代码无法编译。该错误似乎是对合并例程的某种模棱两可的调用。我的理解是,STL在std命名空间中有一个合并例程,但据我所知,下面代码中的名称merge应该是唯一的。如果我将merge重命名为xmerge,一切正常。可能是什么问题?名称冲突从何而来?http://codepad.org/uAKciGy5#include#include#includetemplatevoidmerge(constInputIterator1begin1,constInputIterator1end1,constInputIterator2begin2,constInputIterator2end2,Ou

c++ - 我试图在 C++03 中嵌套 boost 的 "map_list_of",但显然构造不明确?

考虑一下:#include#include#include#includeusingboost::assign::map_list_of;conststd::map>test=map_list_of(100,map_list_of(1,'a')(2,'b'))(101,map_list_of(1,'c')(2,'d'));intmain(){std::coutsecond.find(2)->second我希望结果是一个程序,在执行时输出d.相反,Igetthis:$clang++-std=c++03-O2-Wall-pedantic-pthreadmain.cppInfileinclu

c++ - 不明确的 string::operator= 调用隐式转换为 int 和 string 的类型

给定以下程序:#include#includeusingnamespacestd;structGenericType{operatorstring(){return"HelloWorld";}operatorint(){return111;}operatordouble(){return123.4;}};intmain(){inti=GenericType();strings=GenericType();doubled=GenericType();cout它在VisualStudio11上编译,但不是clang或gcc。它有问题,因为它想从GenericType隐式转换为int为cha

c++ - 模板参数不明确 : could not deduce template argument

我正在做一些看起来像这样的包装器:#includetemplatevoidApply(void(T::*cb)(Value),T*obj,Valuev){(obj->*cb)(v);}classFoo{public:voidMyFunc(constint&i){std::cout我收到这个错误:应用:未找到匹配的重载函数。voidApply(void(__thiscallT::*)(Value),T*,Value):模板参数Value不明确,可能是int或constint&。voidApply(void(__thiscallT::*)(Value),T*,Value):无法从const

c++ - 不明确的符号错误?

intii,maxnum;for(ii=1;iimax){//thepartwhereIgetC2872AmbiguousSymbolerrormax=count[ii];//thepartwhereIgetC2872AmbiguousSymbolerrormaxnum=ii;}}我从来没有遇到过这个错误,这真令人沮丧。 最佳答案 您的变量max与std::max()冲突。尝试使用不同的名称,它应该可以修复该错误。 关于c++-不明确的符号错误?,我们在StackOverflow上找到一

c++ - 为什么此 C++ 代码中的构造函数不明确,我该如何解决?

在下面的代码中,编译器无法确定我要使用哪个构造函数。为什么,我该如何解决这个问题?(Liveexample)#include#include#includetemplateclassA{public:usinga_type=std::tuple;usingb_type=std::tuple;inlineexplicitconstexprA(conststd::function&Initializer,conststd::function&Evaluator,constType1&elem1,constType2&elem2){std::cout&Initializer,conststd

c++ - 为什么这个 operator= 调用不明确?

我正在制作一个带有转发构造函数的瘦派生类。(请耐心等待,我必须使用缺少继承构造函数的GCC4.7.2)。第一次尝试时,我忘记添加explicit关键字,结果出错。有人可以准确解释为什么会出现此特定错误吗?我无法弄清楚事件的顺序。#includetemplatestructshared_ptr:std::shared_ptr{template/*explicit*/shared_ptr(Args&&...args):std::shared_ptr(std::forward(args)...){}};structA{};structConvertsToPtr{shared_ptrptr=s